<template>
  <transition name="fade">
    <div class="notify-container slide-bottom" v-if="notifyShow">

      <div class="notif center" :style="{height:height}">
        <div class="content"><span :style="{fontSize:font+'px'}">{{ msg }}</span></div>
      </div>
      <div class="action-block center" v-if="action">
        <div class="snooze" @click="snoozeTick">×</div>
        <div class="tick" @click="tick">✔</div>
      </div>

    </div>
  </transition>

</template>

<script>
import {mapMutations} from 'vuex';

export default {
  name: "GoNotify",
  props: {
    msg: {
      type: String,
      require: true
    },
    action: {
      type: Boolean,
      default: false
    },
    font: {
      type: Number,
      default: 17
    },
    duration: {
      type: Number,
      default: 1000
    },
    notifyShow: {
      type: Boolean
    },
    height: {
      type: String,
      default: '100px'
    },
    success: {
      type: Function
    },
    snooze: {
      type: Function
    }
  },
  mounted() {
  },
  computed: {},
  methods: {
    ...mapMutations(['activateNotify', 'successNotify']),
    tick() {
      this.successNotify(true);
      this.activateNotify(false);
      if (this.success) {
        this.success();
      }
    },
    snoozeTick() {
      this.successNotify(false);
      this.activateNotify(false);
      if (this.snooze) {
        this.snooze();
      }

    }
  },
  watch: {
    notifyShow(newVal) {
      if (!this.action) {
        if (newVal) {
          setTimeout(() => {
            this.activateNotify(false);
          }, this.duration)
        }
      }
    }
  }
}
</script>

<style lang="less">
@import url("https://fonts.googleapis.com/css?family=Nunito:400,700");


.fade-enter-active, .fade-leave-active {
  transition: opacity .5s;
}

.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}


@keyframes slide-bottom {
  0% {
    transform: translateY(-250px);
  }
  100% {
    transform: translateY(0px);
  }
}

.slide-bottom {
  animation: slide-bottom 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) forwards;
}

.notify-container {
  z-index: 9999;
  font-family: "Nunito", serif;
  position: absolute;
  left: 0;
  right: 0;
  margin: auto;
  padding-top: 20px;
  text-align: center;


  .center {
    position: relative;
    left: 50%;
    transform: translateX(-50%);
  }

  .notif {
    position: relative;
    width: 330px;
    height: 90px;
    border-radius: 20px;
    background: #fff7f7;
  }

  .content, .snooze, .tick {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .snooze, .tick {
    cursor: pointer;
  }

  .content {
    width: 100%;
    height: 100%;
  }

  .content span {
    margin: 30px;
    font-weight: 700;
    color: #333;
    text-align: left;
  }

  .action-block {
    position: relative;
    margin-top: 15px;
    width: 330px;
    height: 46px;
  }

  .snooze {
    position: absolute;
    left: 0;
    width: 67px;
    height: 46px;
    border-radius: 20px;
    background: rgb(238, 105, 94);
  }

  .tick {
    position: absolute;
    font-size: 20px;
    right: 0;
    width: 67px;
    height: 46px;
    border-radius: 20px;
    background: #b0c6a6;
  }

}


</style>